<?php
	class Mtransactions extends Model {
	
		function __construct() {
			parent::Model();
		}
		
		function getAllTransactions() {
			$query = $this->db->get('transactions');
			if ($query->num_rows() > 0){
				return $query->result(); 
			} else {
				show_error('Database is Empty!');
			}  
		}
		
		function getTransaction($id){
			$options = array('id' => $id);
			$query = $this->db->getwhere('transactions',$options,1);
			if ($query->num_rows() > 0){
				return $query->result(); 
			}   
		}
		
		function addTransaction(){
			$data = array( 
				'commodity_id' => $_POST['commodity_id'],
				'user_id' => $_POST['user_id']
			);
			$this->db->insert('transactions', $data);	
		}
		
		function updateTransaction($id){
			$data = array( 
				'commodity_id' => $_POST['commodity_id'],
				'user_id' => $_POST['user_id']
				);
			date_default_timezone_set('Europe/Helsinki');
			//$data['updated_at'] = date ("Y-m-d H:i:s");
			$this->db->where('id', $id);
			$this->db->update('transactions', $data);	
		}
		
		function deleteTransaction($id){
			$this->db->where('id', $id);
			$this->db->delete('transactions');
		}
	}
?>